<template>
  <span @click="open">
    <slot></slot>
  </span>
</template>

<script>
export default {
  props: {
    id: [String, Number],
    url: String,
    parmeId: {
      default: "userId",
      type: String
    },
    info: {
      default: "删除",
      type: String
    },
    init: {
      default: false,
      type: Boolean
    },
  },
  methods: {
    open() {
      this.$confirm("是否确认" + this.info, "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      })
        .then(() => {
          this.$get(this.url, {
            [this.parmeId]: this.id
          }).then(data => {
            if (data.data.success) {
              this.$message({
                type: "success",
                message: data.data.resultDes
              });
              if(this.init){
                this.$emit('init')
              }
            }
            if (!data.data.success) {
              this.$message({
                type: "error",
                message: data.data.resultDes
              });
            }
          });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消"
          });
        });
    }
  }
};
</script>

<style scoped lang="css">
</style>
